//
//  benevolenceController.m
//  SSSAllRollAgency
//
//  Created by Darker on 2017/3/14.
//  Copyright © 2017年 Darker. All rights reserved.
//

#import "benevolenceController.h"
#import "SSSExchangeController.h"
#import "RightToLeftTextField.h"
#import "XHRequestManager.h"
@interface benevolenceController ()<UITextFieldDelegate>
{
    BOOL move;//记录视图是否移动
    UITextField *_textField1;
    RightToLeftTextField *_textField2;
    UILabel *_yLabel;
    UILabel *nuGoodLabel;//剩余善点数
    UILabel *nuCanGoodLabel;//可兑换善点数
    UILabel *nuResGoodLabel;//备用善点
    NSString *typeStr;
    UILabel *bunkName;
    UILabel *_nuBunkLabel;
    NSString *bankId;
    NSString *poundageStr;
    UIButton *commitBtn;//兑换按钮
    NSInteger nu;
}

/** 标签栏当前选中的按钮 */
@property(nonatomic, weak) UIButton *currentBtn;

@end

@implementation benevolenceController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.title = @"我要兑换";
    //去掉透明后导航栏下边的黑边
    //    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor colorWithHex:@"F9F9FA"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //导航栏按钮
    self.navigationItem.rightBarButtonItem=[UIBarButtonItem itemWithTitle:@"兑换记录" color:[UIColor colorWithHex:@"FFFFFF"] target:self action:@selector(toExchange)];
    [self reloadData];
    
    [self setUpApperance];
    
}
- (void)reloadData{
    
    
    [[XHRequestManager manager] getRequest:kConfigPath(kToExchange) params:nil success:^(id  _Nonnull responseObj) {
    
        XHLog(@"-----exchange---%@",responseObj);
        
        if ([responseObj[@"status"] intValue] == 0 ) {
            
            //回到主线程刷新表格
            dispatch_async(dispatch_get_main_queue(), ^{
                
                
                NSMutableArray *dict = [NSMutableArray arrayWithArray:responseObj[@"data"][@"lists"]];
                
                //刷新表格
                nuGoodLabel.text = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"shandian"]];//剩余善点
                nuCanGoodLabel.text = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"enable"]];//可兑换善点
                //nuCan = (long)response[@"data"][@"enable"];
                nuResGoodLabel.text = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"unable"]];//备用善点
                
                nu = dict.count;
                
                if (dict.count == 0) {
                    
                    [QMUITips showError:@"暂未添加银行卡，不能兑换，请前往设置页面个人资料中添加" inView:self.view hideAfterDelay:2];
                    commitBtn.enabled = NO;
                    [commitBtn setBackgroundColor:[UIColor lightGrayColor]];
                    [commitBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                    bunkName.text = @"";//银行卡名称
                    _nuBunkLabel.text = @"";//银行卡号
                    bankId = @"";
                    return ;
                    
                }else{
                    
                    //                    commitBtn.enabled = YES;
                    //                    [commitBtn setBackgroundColor:[UIColor colorWithHex:@"40B87B"]];
                    bunkName.text = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"lists"][0][@"bankName"]];//银行卡名称
                    _nuBunkLabel.text = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"lists"][0][@"bankCardNo"]];//银行卡号
                    bankId = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"lists"][0][@"id"]];
                    
                }
                
            });
            
            
        }else{
            
            [QMUITips showError:responseObj[@"message"] inView:self.view hideAfterDelay:2];
        }

    
     } failure:^(NSError * _Nonnull error) {
    
        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
     }];
    
//    [ZDNetManager zd_requestWithType:ZDHttpRequestTypeGet UrlString:kConfigPath(kToExchange) Parameters:nil SuccessBlock:^(id response) {
//        
//        XHLog(@"-----exchange---%@",response);
//        
//        if ([response[@"status"] intValue] == 0 ) {
//            
//            //回到主线程刷新表格
//            dispatch_async(dispatch_get_main_queue(), ^{
//                
//                NSMutableArray *dict = [NSMutableArray arrayWithArray:response[@"data"][@"lists"]];
//                
//                if (dict.count == 0) {
//                    
//                    [QMUITips showError:@"暂未添加银行卡，不能兑换" inView:self.view hideAfterDelay:2];
//                    commitBtn.enabled = NO;
//                    [commitBtn setBackgroundColor:[UIColor lightGrayColor]];
//                    
//                }else{
//                    
//                    commitBtn.enabled = YES;
//                    [commitBtn setBackgroundColor:[UIColor colorWithHex:@"40B87B"]];
//                }
//                
//                //刷新表格
//                nuGoodLabel.text = [NSString stringWithFormat:@"%@",response[@"data"][@"shandian"]];//剩余善点
//                nuCanGoodLabel.text = [NSString stringWithFormat:@"%@",response[@"data"][@"enable"]];//可兑换善点
//                nuResGoodLabel.text = [NSString stringWithFormat:@"%@",response[@"data"][@"unable"]];//备用善点
//                bunkName.text = [NSString stringWithFormat:@"%@",response[@"data"][@"lists"][0][@"bankName"]];//银行卡名称
//                _nuBunkLabel.text = [NSString stringWithFormat:@"%@",response[@"data"][@"lists"][0][@"bankCardNo"]];//银行卡号
//                bankId = [NSString stringWithFormat:@"%@",response[@"data"][@"lists"][0][@"id"]];
//                
//                bunkName.sd_layout
//                .bottomSpaceToView(_nuBunkLabel,HeigthIos6CompeteWithCurrent(2))
//                .leftEqualToView(_nuBunkLabel)
//                .heightIs(HeigthIos6CompeteWithCurrent(11))
//                .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:bunkName.text font:bunkName.font height:HeigthIos6CompeteWithCurrent(11)]);
//
//            });
//            
//            
//        }else{
//            
//            [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
//        }
//        
//    } FailureBlock:^(NSError *error) {
//        
//        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
//        
//    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
//        
//        
//    }];
    
    
}

- (void)setUpApperance{
    
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor colorWithHex:@"FFFFFF"];
    bgView.layer.masksToBounds = YES;
    bgView.layer.cornerRadius = 5;
    bgView.layer.borderWidth = 0.5;
    bgView.layer.borderColor = [UIColor colorWithHex:@"E5E5E8"].CGColor;
    [self.view addSubview:bgView];
    bgView.sd_layout
    .leftSpaceToView(self.view,WidthIos6CompeteWithCurrent(15))
    .topSpaceToView(self.view,64+HeigthIos6CompeteWithCurrent(9))
    .rightSpaceToView(self.view,WidthIos6CompeteWithCurrent(15))
    .bottomSpaceToView(self.view,HeigthIos6CompeteWithCurrent(34));
    
        UILabel *label = [[UILabel alloc]init];
        label.text = @"兑换善点";
        label.textColor = [UIColor colorWithHex:@"6D6D6D"];
        label.font = [SSSFont systemFontOfSize:15];
        label.textAlignment = NSTextAlignmentLeft;
        [bgView addSubview:label];
        label.sd_layout
        .topSpaceToView(bgView,HeigthIos6CompeteWithCurrent(15))
        .leftSpaceToView(bgView,WidthIos6CompeteWithCurrent(15))
        .heightIs(HeigthIos6CompeteWithCurrent(20))
        .widthIs(WidthIos6CompeteWithCurrent(100));
    
    
    //line
    UIView *lineView1 = [[UIView alloc]init];
    lineView1.backgroundColor = [UIColor colorWithHex:@"E5E5E8"];
    [bgView addSubview:lineView1];
    lineView1.sd_layout
    .topSpaceToView(label,HeigthIos6CompeteWithCurrent(20))
    .leftEqualToView(bgView)
    .rightEqualToView(bgView)
    .heightIs(HeigthIos6CompeteWithCurrent(1));
    
    //今日善心
    UILabel *goodLabel = [[UILabel alloc]init];
    goodLabel.text = @"今日善心";
    goodLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    goodLabel.font = [SSSFont systemFontOfSize:13];
    goodLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:goodLabel];
    goodLabel.sd_layout
    .topSpaceToView(lineView1,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(label)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(100));
    
    //line
    UIView *lineView2 = [[UIView alloc]init];
    lineView2.backgroundColor = [UIColor colorWithHex:@"E5E5E8"];
    [bgView addSubview:lineView2];
    lineView2.sd_layout
    .topSpaceToView(goodLabel,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(goodLabel)
    .rightSpaceToView(bgView,WidthIos6CompeteWithCurrent(10))
    .heightIs(HeigthIos6CompeteWithCurrent(1));

    
    //今日善心
    UILabel *tGoodLabel = [[UILabel alloc]init];
    tGoodLabel.text = [SSSUserManager getUserModel].shanxin;
    tGoodLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];
    tGoodLabel.font = [SSSFont systemFontOfSize:13];
    tGoodLabel.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:tGoodLabel];
    tGoodLabel.sd_layout
    .centerYEqualToView(goodLabel)
    .rightEqualToView(lineView2)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:tGoodLabel.text font:tGoodLabel.font height:HeigthIos6CompeteWithCurrent(20)]);

    
    
    //剩余善点
    UILabel *sGoodLabel = [[UILabel alloc]init];
    sGoodLabel.text = @"剩余善点";
    sGoodLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    sGoodLabel.font = [SSSFont systemFontOfSize:13];
    sGoodLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:sGoodLabel];
    sGoodLabel.sd_layout
    .topSpaceToView(lineView2,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(label)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(100));
  
    

    //line3
    UIView *lineView3 = [[UIView alloc]init];
    lineView3.backgroundColor = [UIColor colorWithHex:@"E5E5E8"];
    [bgView addSubview:lineView3];
    lineView3.sd_layout
    .topSpaceToView(sGoodLabel,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(sGoodLabel)
    .rightSpaceToView(bgView,WidthIos6CompeteWithCurrent(10))
    .heightIs(HeigthIos6CompeteWithCurrent(1));
    
    //剩余善点数
    nuGoodLabel = [[UILabel alloc]init];
    nuGoodLabel.text = @"0";
    nuGoodLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];
    nuGoodLabel.font = [SSSFont systemFontOfSize:13];
    nuGoodLabel.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:nuGoodLabel];
    nuGoodLabel.sd_layout
    .centerYEqualToView(sGoodLabel)
    .rightEqualToView(lineView2)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .leftSpaceToView(sGoodLabel,0);
    
    //可兑换善点
    UILabel *canGoodLabel = [[UILabel alloc]init];
    canGoodLabel.text = @"可兑换善点";
    canGoodLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    canGoodLabel.font = [SSSFont systemFontOfSize:13];
    canGoodLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:canGoodLabel];
    canGoodLabel.sd_layout
    .topSpaceToView(lineView3,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(label)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(100));
    
    //line
    UIView *lineView4 = [[UIView alloc]init];
    lineView4.backgroundColor = [UIColor colorWithHex:@"E5E5E8"];
    [bgView addSubview:lineView4];
    lineView4.sd_layout
    .topSpaceToView(canGoodLabel,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(canGoodLabel)
    .rightSpaceToView(bgView,WidthIos6CompeteWithCurrent(10))
    .heightIs(HeigthIos6CompeteWithCurrent(1));

    
    //可兑换善点数
    nuCanGoodLabel = [[UILabel alloc]init];
    nuCanGoodLabel.text = @"0";
    nuCanGoodLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];
    nuCanGoodLabel.font = [SSSFont systemFontOfSize:13];
    nuCanGoodLabel.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:nuCanGoodLabel];
    nuCanGoodLabel.sd_layout
    .centerYEqualToView(canGoodLabel)
    .rightEqualToView(lineView2)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .leftSpaceToView(canGoodLabel,0);

    //备用善点
    UILabel *resGoodLabel = [[UILabel alloc]init];
    resGoodLabel.text = @"备用善点";
    resGoodLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    resGoodLabel.font = [SSSFont systemFontOfSize:13];
    resGoodLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:resGoodLabel];
    resGoodLabel.sd_layout
    .topSpaceToView(lineView4,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(label)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(100));

    //line
    UIView *lineView5 = [[UIView alloc]init];
    lineView5.backgroundColor = [UIColor colorWithHex:@"E5E5E8"];
    [bgView addSubview:lineView5];
    lineView5.sd_layout
    .topSpaceToView(resGoodLabel,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(resGoodLabel)
    .rightSpaceToView(bgView,WidthIos6CompeteWithCurrent(10))
    .heightIs(HeigthIos6CompeteWithCurrent(1));
    

    //备用善点数
    nuResGoodLabel = [[UILabel alloc]init];
    //nuResGoodLabel.text = @"500";
    nuResGoodLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];
    nuResGoodLabel.font = [SSSFont systemFontOfSize:13];
    nuResGoodLabel.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:nuResGoodLabel];
    nuResGoodLabel.sd_layout
    .centerYEqualToView(resGoodLabel)
    .rightEqualToView(lineView5)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .leftSpaceToView(resGoodLabel,0);
    

    //提现银行
    UILabel *bankLabel = [[UILabel alloc]init];
    bankLabel.text = @"提现银行";
    bankLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    bankLabel.font = [SSSFont systemFontOfSize:13];
    bankLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:bankLabel];
    bankLabel.sd_layout
    .topSpaceToView(lineView5,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(label)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(100));
    
    //line
    UIView *lineView6 = [[UIView alloc]init];
    lineView6.backgroundColor = [UIColor colorWithHex:@"E5E5E8"];
    [bgView addSubview:lineView6];
    lineView6.sd_layout
    .topSpaceToView(bankLabel,HeigthIos6CompeteWithCurrent(15))
    .leftEqualToView(bankLabel)
    .rightSpaceToView(bgView,WidthIos6CompeteWithCurrent(10))
    .heightIs(HeigthIos6CompeteWithCurrent(1));
    
    //银行信息
    _nuBunkLabel = [[UILabel alloc]init];
    _nuBunkLabel.text = @"";
    _nuBunkLabel.textColor= [UIColor colorWithHex:@"BBBBBB"];
    _nuBunkLabel.font = [SSSFont systemFontOfSize:11];
    [bgView addSubview:_nuBunkLabel];
    _nuBunkLabel.sd_layout
    .bottomSpaceToView(lineView6,HeigthIos6CompeteWithCurrent(14))
    .rightEqualToView(lineView6)
    .heightIs(HeigthIos6CompeteWithCurrent(9))
    .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:_nuBunkLabel.text font:_nuBunkLabel.font height:HeigthIos6CompeteWithCurrent(9)]);
    
    bunkName = [[UILabel alloc]init];
    bunkName.text = @"中国工商银行";
    bunkName.textColor= [UIColor colorWithHex:@"BBBBBB"];
    bunkName.font = [SSSFont systemFontOfSize:11];
    [bgView addSubview:bunkName];
//    bunkName.sd_layout
//    .bottomSpaceToView(_nuBunkLabel,HeigthIos6CompeteWithCurrent(2))
//    .leftEqualToView(_nuBunkLabel)
//    .heightIs(HeigthIos6CompeteWithCurrent(11))
//    .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:bunkName.text font:bunkName.font height:HeigthIos6CompeteWithCurrent(11)]);
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:@""];
    [bgView addSubview:imageView];
    imageView.sd_layout
    .topSpaceToView(lineView3,HeigthIos6CompeteWithCurrent(14))
    .bottomSpaceToView(lineView4,HeigthIos6CompeteWithCurrent(13))
    .heightIs(HeigthIos6CompeteWithCurrent(24))
    .rightSpaceToView(_nuBunkLabel,WidthIos6CompeteWithCurrent(3));
    
    NSArray *titleArray = @[@" T1",@" T3",@" T7"];
    CGFloat width = (self.view.frame.size.width - WidthIos6CompeteWithCurrent(50))/3;
    CGFloat height = HeigthIos6CompeteWithCurrent(20);
    for (int index = 0; index<titleArray.count; index++) {
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(index * width + WidthIos6CompeteWithCurrent(50),HeigthIos6CompeteWithCurrent(270)+64, width, height)];
        btn.tag = index + 5000;
        // 文字
        [btn setTitle:titleArray[index] forState:UIControlStateNormal];
        
        btn.titleLabel.font = [SSSFont systemFontOfSize:13];
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        // 颜色
        [btn setTitleColor:[UIColor colorWithHex:@"FFFFFF"] forState:UIControlStateNormal];
        // 按钮不能被点击时的颜色
        [btn setTitleColor:[UIColor redColor] forState:UIControlStateDisabled];
        [btn setImage:[UIImage imageNamed:@"icon_options"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"icon_pitchon"] forState:UIControlStateDisabled];
        
        // 事件
        [btn addTarget:self action:@selector(btnClik:) forControlEvents:UIControlEventTouchUpInside];
        [btn sizeToFit];
        [bgView addSubview:btn];
        // 默认选中第一个按钮
        if (index == 0) {
            typeStr = @"1";
            btn.enabled = NO;
            self.currentBtn = btn;
            // 让按钮那边的label根据文字内容计算尺寸
            [btn.titleLabel sizeToFit]; // 方法1
            //            self.indicatorView.width = [titles[idx] sizeWithAttributes:@{NSFontAttributeName:btn.titleLabel.font}].width;   // 方法2
            
        }
    }

    
    UILabel *_label1 = [[UILabel alloc]init];
    _label1.text = @"元";
    _label1.textColor= [UIColor colorWithHex:@"6D6D6D"];
    _label1.font = [SSSFont systemFontOfSize:12];
    [bgView addSubview:_label1];
    _label1.sd_layout
    .rightSpaceToView(bgView,WidthIos6CompeteWithCurrent(28))
    .topSpaceToView(lineView6,HeigthIos6CompeteWithCurrent(71))
    .heightIs(HeigthIos6CompeteWithCurrent(11))
    .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:_label1.text font:_label1.font height:HeigthIos6CompeteWithCurrent(11)]);
    
    _yLabel = [[UILabel alloc]init];
    _yLabel.text = @"0";
    _yLabel.textAlignment = NSTextAlignmentCenter;
    _yLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];
    _yLabel.font = [SSSFont systemFontOfSize:15];
    //[label1 setValue:[UIColor colorWithHex:@"FFFFFF"] forKeyPath:@"_placeholderLabel.textColor"];
    //_textField2.delegate = self;
    [bgView addSubview:_yLabel];
    _yLabel.sd_layout
    .centerYEqualToView(_label1)
    .rightSpaceToView(_label1,WidthIos6CompeteWithCurrent(5))
    .widthIs(WidthIos6CompeteWithCurrent(103))
    .heightIs(HeigthIos6CompeteWithCurrent(31));
    _yLabel.layer.borderColor = [UIColor colorWithHex:@"BBBBBB"].CGColor;
    _yLabel.layer.borderWidth = 0.5;
    _yLabel.layer.cornerRadius = 5;
    _yLabel.layer.masksToBounds = YES;

    
    UILabel *isLabel = [[UILabel alloc]init];
    isLabel.text = @"=";
    isLabel.textColor= [UIColor colorWithHex:@"BBBBBB"];
    isLabel.font = [SSSFont systemFontOfSize:18];
    [bgView addSubview:isLabel];
    isLabel.sd_layout
    .rightSpaceToView(_yLabel,WidthIos6CompeteWithCurrent(9))
    .centerYEqualToView(_yLabel)
    .heightIs(HeigthIos6CompeteWithCurrent(11))
    .widthIs(WidthIos6CompeteWithCurrent(11));
    
    
    
    _textField1 = [[UITextField alloc]init];
    _textField1.placeholder = @"请输入要兑换的善点数";
    [_textField1 setValue:[NSNumber numberWithInt:15] forKey:@"paddingLeft"];
    _textField1.textColor = [UIColor blackColor];
    _textField1.delegate = self;
    [bgView addSubview:_textField1];
    _textField1.sd_layout
    .centerYEqualToView(isLabel)
    .rightSpaceToView(isLabel,WidthIos6CompeteWithCurrent(9))
    .widthIs(WidthIos6CompeteWithCurrent(143))
    .heightIs(HeigthIos6CompeteWithCurrent(31));
    _textField1.layer.borderColor = [UIColor colorWithHex:@"BBBBBB"].CGColor;
    _textField1.layer.borderWidth = 0.5;
    _textField1.layer.cornerRadius = 5;
    _textField1.layer.masksToBounds = YES;
    [_textField1 setValue:[UIColor colorWithHex:@"BBBBBB"] forKeyPath:@"_placeholderLabel.textColor"];
    [_textField1 setValue:[SSSFont systemFontOfSize:10] forKeyPath:@"_placeholderLabel.font"];
    _textField1.font = [SSSFont systemFontOfSize:10];
    UILabel *_label2 = [[UILabel alloc]init];
    _label2.text = @"提示：提现金额=可兑换善点数x善心";
    _label2.textColor = [UIColor colorWithHex:@"6D6D6D"];
    _label2.font = [SSSFont systemFontOfSize:12];
    [bgView addSubview:_label2];
    _label2.sd_layout
    .rightEqualToView(_label1)
    .topSpaceToView(_textField1,HeigthIos6CompeteWithCurrent(5))
    .heightIs(HeigthIos6CompeteWithCurrent(12))
    .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:_label2.text font:_label2.font height:HeigthIos6CompeteWithCurrent(12)]);
    
    //提交按钮
    //兑换按钮
    commitBtn = [[UIButton alloc]init];
    [commitBtn setBackgroundColor:[UIColor colorWithHex:@"40B87B"]];
    [commitBtn setTitle:@"提 交" forState:UIControlStateNormal];
    commitBtn.titleLabel.font = [SSSFont systemFontOfSize:18];
    commitBtn.enabled = NO;
    [commitBtn setBackgroundColor:[UIColor lightGrayColor]];
    [commitBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [bgView addSubview:commitBtn];
    [commitBtn addTarget:self action:@selector(commitBtnClick) forControlEvents:UIControlEventTouchDown];
    commitBtn.sd_layout
    .topSpaceToView(_label2,HeigthIos6CompeteWithCurrent(43))
    .centerXEqualToView(bgView)
    .widthIs(WidthIos6CompeteWithCurrent(290))
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    commitBtn.layer.masksToBounds = YES;
    commitBtn.layer.cornerRadius = 6;
}
- (void)btnClik:(UIButton *)button{
    
    self.currentBtn.enabled = YES;
    button.enabled = NO;
    self.currentBtn = button;
    switch (self.currentBtn.tag - 5000) {
        case 0:
            typeStr = @"1";
            if (![_textField1.text isEqualToString:@""]) {
                [self reloadCalculateData];
                
            }else{
                
                return;
            }

            break;
        case 1:
            typeStr = @"3";
            if (![_textField1.text isEqualToString:@""]) {
                [self reloadCalculateData];
                
            }else{
                
                return;
            }

            break;
        case 2:
            typeStr = @"7";
            if (![_textField1.text isEqualToString:@""]) {
                [self reloadCalculateData];
                
            }else{
                
                return;
            }

            break;
            
        default:
            break;
    }
}

- (void)toExchange{
    
    SSSExchangeController *exchangeVc = [[SSSExchangeController alloc]init];
    [self.navigationController pushViewController:exchangeVc animated:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField;{
    
    if (_textField1.text.length > 0) {
        
        [commitBtn setBackgroundColor:[UIColor colorWithHex:@"40B87B"]];
        [commitBtn setTitleColor:[UIColor colorWithHex:@"FFFFFF"] forState:UIControlStateNormal];
        commitBtn.enabled = YES;
        [self reloadCalculateData];
    }else{
        
        [commitBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [commitBtn setBackgroundColor:[UIColor lightGrayColor]];
        commitBtn.enabled = NO;
        
    }
    
}
#pragma mark - 提交按钮点击
- (void)commitBtnClick{
    
    if (nu == 0) {
        
        [QMUITips showError:@"暂未添加银行卡，不能兑换，请前往设置页面个人资料中添加" inView:self.view hideAfterDelay:2];
        commitBtn.enabled = NO;
        [commitBtn setBackgroundColor:[UIColor lightGrayColor]];
        [commitBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

        return;
        
    }else{
        
        
        if ([_textField1.text isEqualToString: @""]) {
            
            [QMUITips showError:@"请输入要兑换的善点数" inView:self.view hideAfterDelay:2];
            return;
            
        }else{
            
            [self reloadExchangeGoodNuData];
        }

    }
    
}
/**
 *  点击空白处，让键盘消失
 *
 *  @param touches 手指触摸的地方
 *  @param event   手指触摸
 */
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    // 让所有的文本框放弃第一响应者
    [_textField2 resignFirstResponder];
    [_textField1 resignFirstResponder];
    [self isMoveUp];
}
#pragma mark----UITextFieldDelegate回调方法
// 文本框开始编辑的回调方法
- (void)textFieldDidBeginEditing:(UITextField *)textField {
    if (!move) {
        //        CGRect frame1 = button.frame;
        //        CGFloat y1 = frame1.origin.y;
        //        y1 -= 100;
        //        frame1.origin.y = y1;
        //        button.frame = frame1;
        NSArray *subViewsArray = self.view.subviews;
        [subViewsArray enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            CGRect frame = obj.frame;
            CGFloat y = frame.origin.y;
            y -= 100;
            frame.origin.y = y;
            obj.frame = frame;
        }];
    }
    move = YES;
}

/**
 *  如果子视图已经向上移动的回调方法
 */
- (void)isMoveUp {
    if (move) {
        //        CGRect frame1 = button.frame;
        //        CGFloat y1 = frame1.origin.y;
        //        y1 += 100;
        //        frame1.origin.y = y1;
        //        button.frame = frame1;
        NSArray *subViewsArray = self.view.subviews;
        [subViewsArray enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            CGRect frame = obj.frame;
            CGFloat y = frame.origin.y;
            y += 100;
            frame.origin.y = y;
            obj.frame = frame;
        }];
        move = NO;
    }
}
- (void)reloadCalculateData{
    
    if ((NSInteger)_textField1.text > (NSInteger)nuCanGoodLabel.text) {
        
        [QMUITips showError:@"善点不足" inView:self.view hideAfterDelay:2];
        return;
        
    }else if (nu == 0){
        
        [QMUITips showError:@"暂未添加银行卡，不能兑换，请前往设置页面个人资料中添加" inView:self.view hideAfterDelay:2];
        commitBtn.enabled = NO;
        [commitBtn setBackgroundColor:[UIColor lightGrayColor]];
        [commitBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        
    }else{
        
        [commitBtn setBackgroundColor:[UIColor colorWithHex:@"40B87B"]];
        [commitBtn setTitleColor:[UIColor colorWithHex:@"FFFFFF"] forState:UIControlStateNormal];
        commitBtn.enabled = YES;
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        params[@"shandian"] = _textField1.text;
        params[@"arrivalMode"] = typeStr;
        
       [[XHRequestManager manager] getRequest:kConfigPath(kGetRealMoney) params:params success:^(id  _Nonnull responseObj) {
           
           XHLog (@"----response---%@",responseObj);
           
           if ([responseObj[@"status"] intValue] == 0 ) {
               
               if ([responseObj[@"data"][@"realMoney"] integerValue] < 10000) {
                   
                   _yLabel.text = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"realMoney"]];
                   
               }else{
                   
                   _yLabel.text = [NSString stringWithFormat:@"%.2ld",[responseObj[@"data"][@"realMoney"] integerValue]/10000];
               }

               poundageStr = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"poundage"]];
           }else{
               
               [QMUITips showError:responseObj[@"message"] inView:self.view hideAfterDelay:2];
           }

           
       } failure:^(NSError * _Nonnull error) {
           
           XHLog(@"%@",error.localizedDescription);
           [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];

       }];
        
//        [ZDNetManager zd_requestWithType:ZDHttpRequestTypeGet UrlString:kConfigPath(kGetRealMoney) Parameters:params SuccessBlock:^(id response) {
//            
//            XHLog (@"----response---%@",response);
//            
//            if ([response[@"status"] intValue] == 0 ) {
//                
//                _yLabel.text = [NSString stringWithFormat:@"%@",response[@"data"][@"realMoney"]];
//                poundageStr = [NSString stringWithFormat:@"%@",response[@"data"][@"poundage"]];
//            }else{
//                
//                [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
//            }
//            
//        } FailureBlock:^(NSError *error) {
//            
//            XHLog(@"%@",error.localizedDescription);
//            [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
//            
//        } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
//            
//            
//        }];
        
    }

}
- (void)reloadExchangeGoodNuData{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"shandian"] = _textField1.text;
    params[@"bankId"] = bankId;
    params[@"poundage"] = poundageStr;
    params[@"realMoney"] = _yLabel.text;
    params[@"arrivalMode"] = typeStr;
    
    [[XHRequestManager manager] postRequest:kConfigPath(kExchange) params:params success:^(id  _Nonnull response) {
        XHLog (@"----response---%@",response);
        if ([response[@"status"] intValue] == 0 ) {
            
            [QMUITips showSucceed:@"兑换成功" inView:self.view hideAfterDelay:2];
            
            NSDictionary *dict = @{@"unbaleNu":[NSString stringWithFormat:@"%@",response[@"data"][@"unable"]],@"shandianNu":[NSString stringWithFormat:@"%@",response[@"data"][@"shandian"]]};
            //发送通知传值
            NSNotification *notification =[NSNotification notificationWithName:@"sendShandian" object:nil userInfo:dict];
            [[NSNotificationCenter defaultCenter] postNotification:notification];
            
        }else{
            
            [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
        }
    } failure:^(NSError * _Nonnull error) {
        
        XHLog(@"%@",error.localizedDescription);
        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
    }];
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"sendShandian" object:nil];
}

@end
